unit uFilterPeriod;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, ComCtrls, StdCtrls, DateUtils, ExtCtrls;

type
  TfFilterPeriod = class(TForm)
    Label1: TLabel;
    Label2: TLabel;
    DateTimePicker1: TDateTimePicker;
    DateTimePicker2: TDateTimePicker;
    Panel1: TPanel;
    Bevel1: TBevel;
    Panel2: TPanel;
    Button3: TButton;
    Button4: TButton;
    ComboBox1: TComboBox;
    Label3: TLabel;
    procedure Button2Click(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure Button1Click(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure ComboBox1CloseUp(Sender: TObject);
  private
  public
    IsDataSet, IsFormClosed: Boolean;
  end;

var
  fFilterPeriod: TfFilterPeriod;

implementation

{$R *.dfm}

procedure TfFilterPeriod.Button2Click(Sender: TObject);
begin
  IsDataSet := False;
  IsFormClosed := True;
  Close();
end;

procedure TfFilterPeriod.FormCreate(Sender: TObject);
begin
  DateTimePicker1.Date := StartOfTheMonth(Date());
  DateTimePicker2.Date := EndOfTheMonth(Date());
end;

procedure TfFilterPeriod.Button1Click(Sender: TObject);
begin
  IsDataSet := True;
  IsFormClosed := True;
  Close();
end;

procedure TfFilterPeriod.FormShow(Sender: TObject);
begin
  IsDataSet := False;
  IsFormClosed := False;
  DateTimePicker1.SetFocus();
end;

procedure TfFilterPeriod.ComboBox1CloseUp(Sender: TObject);
begin
  if((Sender as TComboBox).ItemIndex = 0) then
  begin
    DateTimePicker2.Date := DateTimePicker1.Date;
  end;
  if((Sender as TComboBox).ItemIndex = 1) then
  begin
    DateTimePicker1.Date := StartOfTheMonth(Date());
    DateTimePicker2.Date := EndOfTheMonth(Date());
  end;
  if((Sender as TComboBox).ItemIndex = 2) then
  begin
    DateTimePicker1.Date := StartOfTheYear(Date());
    DateTimePicker2.Date := EndOfTheYear(Date());
  end;
end;

end.
